package com.kefu.admin.utils;

import com.google.common.collect.ImmutableMap;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * User:
 * Date: 2016-11-11
 * Description: No Description
 */
public class TgqmdjPinJi {
    private static final Map<String, String> mapOne = ImmutableMap.<String, String>builder()
            .put("甲子", "阳仲金")
            .put("乙丑", "阳仲金")
            .put("丙寅", "阴孟火")
            .put("丁卯", "阴孟火")
            .put("戊辰", "阳季木")
            .put("己巳", "阳季木")
            .put("庚午", "阴仲土")
            .put("辛未", "阴仲土")
            .put("壬申", "阳孟金")
            .put("癸酉", "阳孟金")
            .put("甲戌", "阴季火")
            .put("乙亥", "阴季火")
            .put("丙子", "阳仲水")
            .put("丁丑", "阳仲水")
            .put("戊寅", "阴孟土")
            .put("己卯", "阴孟土")
            .put("庚辰", "阳季金")
            .put("辛巳", "阳季金")
            .put("壬午", "阴仲木")
            .put("癸未", "阴仲木")
            .put("甲申", "阳孟水")
            .put("乙酉", "阳孟水")
            .put("丙戌", "阴季土")
            .put("丁亥", "阴季土")
            .put("戊子", "阳仲火")
            .put("己丑", "阳仲火")
            .put("庚寅", "阴孟木")
            .put("辛卯", "阴孟木")
            .put("壬辰", "阳季水")
            .put("癸巳", "阳季水")
            .put("甲午", "阴仲金")
            .put("乙未", "阴仲金")
            .put("丙申", "阳孟火")
            .put("丁酉", "阳孟火")
            .put("戊戌", "阴季木")
            .put("己亥", "阴季木")
            .put("庚子", "阳仲土")
            .put("辛丑", "阳仲土")
            .put("壬寅", "阴孟金")
            .put("癸卯", "阴孟金")
            .put("甲辰", "阳季火")
            .put("乙巳", "阳季火")
            .put("丙午", "阴仲水")
            .put("丁未", "阴仲水")
            .put("戊申", "阳孟土")
            .put("己酉", "阳孟土")
            .put("庚戌", "阴季金")
            .put("辛亥", "阴季金")
            .put("壬子", "阳仲木")
            .put("癸丑", "阳仲木")
            .put("甲寅", "阴孟水")
            .put("乙卯", "阴孟水")
            .put("丙辰", "阳季土")
            .put("丁巳", "阳季土")
            .put("戊午", "阴仲火")
            .put("己未", "阴仲火")
            .put("庚申", "阳孟木")
            .put("辛酉", "阳孟木")
            .put("壬戌", "阴季水")
            .put("癸亥", "阴季水")
            .build();
    private static final List<String> jiazi = Arrays.asList(
            "甲子",
            "乙丑",
            "丙寅",
            "丁卯",
            "戊辰",
            "己巳",
            "庚午",
            "辛未",
            "壬申",
            "癸酉",
            "甲戌",
            "乙亥",
            "丙子",
            "丁丑",
            "戊寅",
            "己卯",
            "庚辰",
            "辛巳",
            "壬午",
            "癸未",
            "甲申",
            "乙酉",
            "丙戌",
            "丁亥",
            "戊子",
            "己丑",
            "庚寅",
            "辛卯",
            "壬辰",
            "癸巳",
            "甲午",
            "乙未",
            "丙申",
            "丁酉",
            "戊戌",
            "己亥",
            "庚子",
            "辛丑",
            "壬寅",
            "癸卯",
            "甲辰",
            "乙巳",
            "丙午",
            "丁未",
            "戊申",
            "己酉",
            "庚戌",
            "辛亥",
            "壬子",
            "癸丑",
            "甲寅",
            "乙卯",
            "丙辰",
            "丁巳",
            "戊午",
            "己未",
            "庚申",
            "辛酉",
            "壬戌",
            "癸亥");

    private static final List<String> yinpan = Arrays.asList(
            "九天","阏缝","穷奇","饮原","赤奋若","天蓬","白泽","梼杌","狍鸮","提摄格",
            "天芮","旃蒙","狰","槐知","单阏","太阳","柔兆","狞","魑","执徐",
            "天冲","强围","犬因","魅","大荒落","天辅","著雍","亡","魍","敦祥",
            "九地","天禽","甪端","蜚瘟","魉","协洽","天心","屠维","虚耗","鬼车",
            "涒滩","天柱","上章","傲狠","作噩","太阴","昭阳","诸怀","淹茂","天任",
            "重光","九婴","大渊献","天英","元黓","飞廉","空","天罡","朱厌","困敦");



    public  List<PinJiData> getResult(Integer yinyang,String yinpankaiyuan,String jiazikaiyuan){
        List<PinJiData> lists = new ArrayList<>();
        int yindex = yinpan.indexOf(yinpankaiyuan);
        int jindex = jiazi.indexOf(jiazikaiyuan);
        if(0>yindex||0>jindex){
            return lists;
        }
        List<String> tempyinpan = new ArrayList<>();
        List<String> tempjiazi = new ArrayList<>();
        for(int i=yindex;i<yinpan.size();i++){
            tempyinpan.add(yinpan.get(i));
        }
        for(int i=0;i<yindex;i++){
            tempyinpan.add(yinpan.get(i));
        }
        for(int i=jindex;i<jiazi.size();i++){
            tempjiazi.add(jiazi.get(i));
        }
        for(int i=0;i<jindex;i++){
            tempjiazi.add(jiazi.get(i));
        }
        if(1==yinyang){// 阴遁
            PinJiData pg = new PinJiData();
            pg.setZhuguan("偏官-困敦");
            pg.setZhuguanYinlv(getyinLv("困敦",tempyinpan,tempjiazi));
            pg.setShiguan("偏禄-大渊献");
            pg.setShiguanYinlv(getyinLv("大渊献",tempyinpan,tempjiazi));
            lists.add(getBiPinJi(pg));
            PinJiData pg1 = new PinJiData();
            pg1.setZhuguan("官-提摄格");
            pg1.setZhuguanYinlv(getyinLv("提摄格",tempyinpan,tempjiazi));
            pg1.setShiguan("禄-单阏");
            pg1.setShiguanYinlv(getyinLv("单阏",tempyinpan,tempjiazi));
            lists.add(getBiPinJi(pg1));
            PinJiData pg2 = new PinJiData();
            pg2.setZhuguan("财-大荒落");
            pg2.setZhuguanYinlv(getyinLv("大荒落",tempyinpan,tempjiazi));
            pg2.setShiguan("斗-敦祥");
            pg2.setShiguanYinlv(getyinLv("敦祥",tempyinpan,tempjiazi));
            lists.add(getBiPinJi(pg2));
            PinJiData pg3 = new PinJiData();
            pg3.setZhuguan("财-大荒落");
            pg3.setZhuguanYinlv(getyinLv("大荒落",tempyinpan,tempjiazi));
            pg3.setShiguan("力-执徐");
            pg3.setShiguanYinlv(getyinLv("执徐",tempyinpan,tempjiazi));
            lists.add(getBiPinJi(pg3));
            PinJiData pg4 = new PinJiData();
            pg4.setZhuguan("业-赤奋若");
            pg4.setZhuguanYinlv(getyinLv("赤奋若",tempyinpan,tempjiazi));
            pg4.setShiguan("力-执徐");
            pg4.setShiguanYinlv(getyinLv("执徐",tempyinpan,tempjiazi));
            lists.add(getBiPinJi(pg4));
            PinJiData pg5 = new PinJiData();
            pg5.setZhuguan("业-赤奋若");
            pg5.setZhuguanYinlv(getyinLv("赤奋若",tempyinpan,tempjiazi));
            pg5.setShiguan("禄-单阏");
            pg5.setShiguanYinlv(getyinLv("单阏",tempyinpan,tempjiazi));
            lists.add(getBiPinJi(pg5));
            PinJiData pg6 = new PinJiData();
            pg6.setZhuguan("刀-涒滩");
            pg6.setZhuguanYinlv(getyinLv("涒滩",tempyinpan,tempjiazi));
            pg6.setShiguan("兵-作噩");
            pg6.setShiguanYinlv(getyinLv("作噩",tempyinpan,tempjiazi));
            lists.add(getBiPinJi(pg6));
            PinJiData pg7 = new PinJiData();
            pg7.setZhuguan("兵-作噩");
            pg7.setZhuguanYinlv(getyinLv("作噩",tempyinpan,tempjiazi));
            pg7.setShiguan("变-淹茂");
            pg7.setShiguanYinlv(getyinLv("淹茂",tempyinpan,tempjiazi));
            lists.add(getBiPinJi(pg7));
            PinJiData pg8 = new PinJiData();
            pg8.setZhuguan("事-协洽");
            pg8.setZhuguanYinlv(getyinLv("协洽",tempyinpan,tempjiazi));
            pg8.setShiguan("变-淹茂");
            pg8.setShiguanYinlv(getyinLv("淹茂",tempyinpan,tempjiazi));
            lists.add(getBiPinJi(pg8));
            PinJiData pg9 = new PinJiData();
            pg9.setZhuguan("事-协洽");
            pg9.setZhuguanYinlv(getyinLv("协洽",tempyinpan,tempjiazi));
            pg9.setShiguan("斗-敦祥");
            pg9.setShiguanYinlv(getyinLv("敦祥",tempyinpan,tempjiazi));
            lists.add(getBiPinJi(pg9));
        }else if(2==yinyang){// 阳遁
            PinJiData pg1 = new PinJiData();
            pg1.setZhuguan("官-阏缝");
            pg1.setZhuguanYinlv(getyinLv("阏缝",tempyinpan,tempjiazi));
            pg1.setShiguan("禄-旃蒙");
            pg1.setShiguanYinlv(getyinLv("旃蒙",tempyinpan,tempjiazi));
            lists.add(getBiPinJi(pg1));
            PinJiData pg2 = new PinJiData();
            pg2.setZhuguan("财-柔兆");
            pg2.setZhuguanYinlv(getyinLv("柔兆",tempyinpan,tempjiazi));
            pg2.setShiguan("斗-强围");
            pg2.setShiguanYinlv(getyinLv("强围",tempyinpan,tempjiazi));
            lists.add(getBiPinJi(pg2));
            PinJiData pg3 = new PinJiData();
            pg3.setZhuguan("财-柔兆");
            pg3.setZhuguanYinlv(getyinLv("柔兆",tempyinpan,tempjiazi));
            pg3.setShiguan("力-屠维");
            pg3.setShiguanYinlv(getyinLv("屠维",tempyinpan,tempjiazi));
            lists.add(getBiPinJi(pg3));
            PinJiData pg4 = new PinJiData();
            pg4.setZhuguan("业-著雍");
            pg4.setZhuguanYinlv(getyinLv("著雍",tempyinpan,tempjiazi));
            pg4.setShiguan("力-屠维");
            pg4.setShiguanYinlv(getyinLv("屠维",tempyinpan,tempjiazi));
            lists.add(getBiPinJi(pg4));
            PinJiData pg5 = new PinJiData();
            pg5.setZhuguan("业-著雍");
            pg5.setZhuguanYinlv(getyinLv("著雍",tempyinpan,tempjiazi));
            pg5.setShiguan("禄-旃蒙");
            pg5.setShiguanYinlv(getyinLv("旃蒙",tempyinpan,tempjiazi));
            lists.add(getBiPinJi(pg5));
            PinJiData pg6 = new PinJiData();
            pg6.setZhuguan("刀-上章");
            pg6.setZhuguanYinlv(getyinLv("上章",tempyinpan,tempjiazi));
            pg6.setShiguan("兵-重光");
            pg6.setShiguanYinlv(getyinLv("重光",tempyinpan,tempjiazi));
            lists.add(getBiPinJi(pg6));
            PinJiData pg7 = new PinJiData();
            pg7.setZhuguan("兵-重光");
            pg7.setZhuguanYinlv(getyinLv("重光",tempyinpan,tempjiazi));
            pg7.setShiguan("变-昭阳");
            pg7.setShiguanYinlv(getyinLv("昭阳",tempyinpan,tempjiazi));
            lists.add(getBiPinJi(pg7));
            PinJiData pg8 = new PinJiData();
            pg8.setZhuguan("事-元黓");
            pg8.setZhuguanYinlv(getyinLv("元黓",tempyinpan,tempjiazi));
            pg8.setShiguan("变-昭阳");
            pg8.setShiguanYinlv(getyinLv("昭阳",tempyinpan,tempjiazi));
            lists.add(getBiPinJi(pg8));
            PinJiData pg9 = new PinJiData();
            pg9.setZhuguan("事-元黓");
            pg9.setZhuguanYinlv(getyinLv("元黓",tempyinpan,tempjiazi));
            pg9.setShiguan("斗-强围");
            pg9.setShiguanYinlv(getyinLv("强围",tempyinpan,tempjiazi));
            lists.add(getBiPinJi(pg9));
        }
        return lists;
    }


    public static void main(String[] args) {
        TgqmdjPinJi pj = new TgqmdjPinJi();
        //List<PinJiData> result = pj.getResult(1, "赤奋若", "庚午");
        //List<PinJiData> result = pj.getResult(1, "单阏", "辛卯");
        //List<PinJiData> result = pj.getResult(2, "魍", "壬戌");
        List<PinJiData> result = pj.getResult(1, "阏缝", "庚辰");
        for (int i = 0; i < result.size(); i++) {
            System.out.println(result.get(i).toString());
        }
    }

    private String getyinLv(String name,List<String> tempyinpan,List<String> tempjiazi){
        // 因为是圆形，故重新生成一个list
        int index = tempyinpan.indexOf(name);
        if(0>index){
            return "";
        }
        String jiazidata = tempjiazi.get(index);
        return jiazidata.concat("(").concat(mapOne.get(jiazidata)).concat(")");
    }

    private static final List<String> lastsheng = Arrays.asList("木火","火土","土金","金水","水木");
    private static final List<String> lastbeisheng = Arrays.asList("火木","土火","金土","水金","木水");
    private static final List<String> lastke = Arrays.asList("金木","木土","土水","水火","火金");
    private static final List<String> lastbeike = Arrays.asList("木金","土木","水土","火水","金火");
    private static final List<String> mengzhongji = Arrays.asList("季","仲","孟");

    private PinJiData getBiPinJi(PinJiData pg){
        /*String last1 = pg.getShiguanYinlv().substring(2,3);
        String last2 = pg.getZhuguanYinlv().substring(2,3);
        String meng1 = pg.getShiguanYinlv().substring(1,2);
        String meng2 = pg.getZhuguanYinlv().substring(1,2);
        String yin1 = pg.getShiguanYinlv().substring(0,1);
        String yin2 = pg.getZhuguanYinlv().substring(0,1);*/
        String shiguanzhi = pg.getShiguanYinlv().split("\\(")[1];
        String zhuguanzhi = pg.getZhuguanYinlv().split("\\(")[1];
        String last1 = shiguanzhi.substring(2,3);
        String last2 = zhuguanzhi.substring(2,3);
        String meng1 = shiguanzhi.substring(1,2);
        String meng2 = zhuguanzhi.substring(1,2);
        String yin1 = shiguanzhi.substring(0,1);
        String yin2 = zhuguanzhi.substring(0,1);
        String temp = last1.concat(last2);
        if(last1.equals(last2)){// 比和
            pg.setShengkeguanxi("比和");
            if(yin1.equals(yin2)){
                pg.setYinYangZhengQi("上");
            }else {
                pg.setYinYangZhengQi("中");
            }
            if(meng1.equals(meng2)){
                pg.setMengzhongji("上");
            }else {
                pg.setMengzhongji("中");
            }
            pg.setPinjiResult(pg.getYinYangZhengQi().concat(pg.getMengzhongji()).concat("品"));
        }else if(lastsheng.contains(temp)){ // 生
            pg.setShengkeguanxi("生");
            int index1 = mengzhongji.indexOf(meng1);
            int index2 = mengzhongji.indexOf(meng2);
            pg.setMengzhongji("下");
            if(index1>index2){
                pg.setMengzhongji("上");
            }else if(index1==index2){
                pg.setMengzhongji("中");
            }
            pg.setYinYangZhengQi("下");
            if(yin1.equals("阴")&&yin2.equals("阳")){
                pg.setYinYangZhengQi("上");
            }else if(yin1.equals(yin2)){
                pg.setYinYangZhengQi("中");
            }
            pg.setPinjiResult(pg.getYinYangZhengQi().concat(pg.getMengzhongji()).concat("品"));
        }else if(lastbeisheng.contains(temp)){ //被生
            pg.setShengkeguanxi("被生");
            int index1 = mengzhongji.indexOf(meng1);
            int index2 = mengzhongji.indexOf(meng2);
            pg.setMengzhongji("下");
            if(index1<index2){
                pg.setMengzhongji("上");
            }else if(index1==index2){
                pg.setMengzhongji("中");
            }
            pg.setYinYangZhengQi("下");
            if(yin1.equals("阳")&&yin2.equals("阴")){
                pg.setYinYangZhengQi("上");
            }else if(yin1.equals(yin2)){
                pg.setYinYangZhengQi("中");
            }
            pg.setPinjiResult(pg.getYinYangZhengQi().concat(pg.getMengzhongji()).concat("品"));
        }else if(lastke.contains(temp)){ // 克
            pg.setShengkeguanxi("克");
            int index1 = mengzhongji.indexOf(meng1);
            int index2 = mengzhongji.indexOf(meng2);
            pg.setMengzhongji("下");
            if(index1>index2){
                pg.setMengzhongji("上");
            }else if(index1==index2){
                pg.setMengzhongji("中");
            }
            pg.setYinYangZhengQi("下");
            if(yin1.equals("阳")&&yin2.equals("阴")){
                pg.setYinYangZhengQi("上");
            }else if(yin1.equals(yin2)){
                pg.setYinYangZhengQi("中");
            }
            pg.setPinjiResult(pg.getYinYangZhengQi().concat(pg.getMengzhongji()).concat("品"));
        }else if(lastbeike.contains(temp)){ //被克
            pg.setShengkeguanxi("被克");
            int index1 = mengzhongji.indexOf(meng1);
            int index2 = mengzhongji.indexOf(meng2);
            pg.setMengzhongji("下");
            if(index1<index2){
                pg.setMengzhongji("上");
            }else if(index1==index2){
                pg.setMengzhongji("中");
            }
            pg.setYinYangZhengQi("下");
            if(yin1.equals("阴")&&yin2.equals("阳")){
                pg.setYinYangZhengQi("上");
            }else if(yin1.equals(yin2)){
                pg.setYinYangZhengQi("中");
            }
            pg.setPinjiResult(pg.getYinYangZhengQi().concat(pg.getMengzhongji()).concat("品"));
        }
        return pg;
    }

    public class  PinJiData{


        private int id;
        /**
         * 主官
         */
        private String zhuguan;

        /**
         * 侍官
         */
        private String shiguan;

        /**
         * 主官音律
         */
        private String zhuguanYinlv;

        /**
         * 侍官音律
         */
        private String shiguanYinlv;

        /**
         * 阴阳争气
         */
        private String yinYangZhengQi;

        /**
         * 孟仲季争气
         */
        private String mengzhongji;

        /**
         * 生克关系
         */
        private String shengkeguanxi;

        /**
         * 品级结果
         */
        private String pinjiResult;


        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getZhuguan() {
            return zhuguan;
        }

        public void setZhuguan(String zhuguan) {
            this.zhuguan = zhuguan;
        }

        public String getShiguan() {
            return shiguan;
        }

        public void setShiguan(String shiguan) {
            this.shiguan = shiguan;
        }

        public String getZhuguanYinlv() {
            return zhuguanYinlv;
        }

        public void setZhuguanYinlv(String zhuguanYinlv) {
            this.zhuguanYinlv = zhuguanYinlv;
        }

        public String getShiguanYinlv() {
            return shiguanYinlv;
        }

        public void setShiguanYinlv(String shiguanYinlv) {
            this.shiguanYinlv = shiguanYinlv;
        }

        public String getYinYangZhengQi() {
            return yinYangZhengQi;
        }

        public void setYinYangZhengQi(String yinYangZhengQi) {
            this.yinYangZhengQi = yinYangZhengQi;
        }

        public String getMengzhongji() {
            return mengzhongji;
        }

        public void setMengzhongji(String mengzhongji) {
            this.mengzhongji = mengzhongji;
        }

        public String getShengkeguanxi() {
            return shengkeguanxi;
        }

        public void setShengkeguanxi(String shengkeguanxi) {
            this.shengkeguanxi = shengkeguanxi;
        }

        public String getPinjiResult() {
            return pinjiResult;
        }

        public void setPinjiResult(String pinjiResult) {
            this.pinjiResult = pinjiResult;
        }

        @Override
        public String toString() {
            return "PinJiData{" +
                    "zhuguan='" + zhuguan + '\'' +
                    ", shiguan='" + shiguan + '\'' +
                    ", zhuguanYinlv='" + zhuguanYinlv + '\'' +
                    ", shiguanYinlv='" + shiguanYinlv + '\'' +
                    ", yinYangZhengQi='" + yinYangZhengQi + '\'' +
                    ", mengzhongji='" + mengzhongji + '\'' +
                    ", shengkeguanxi='" + shengkeguanxi + '\'' +
                    ", pinjiResult='" + pinjiResult + '\'' +
                    '}';
        }
    }
}

